﻿using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;

namespace tju.cme.BookStore2024.webapi.Models.EF;

public partial class BookStore2024Context : DbContext
{
    public BookStore2024Context()
    {
    }

    public BookStore2024Context(DbContextOptions<BookStore2024Context> options)
        : base(options)
    {
    }

    public virtual DbSet<T001reader> T001readers { get; set; }

    public virtual DbSet<T002readerNovel> T002readerNovels { get; set; }

    public virtual DbSet<T011author> T011authors { get; set; }

    public virtual DbSet<T021chiefAdministrator> T021chiefAdministrators { get; set; }

    public virtual DbSet<T022administrator> T022administrators { get; set; }

    public virtual DbSet<T031novel> T031novels { get; set; }

    public virtual DbSet<T032chapter> T032chapters { get; set; }

    public virtual DbSet<T041message> T041messages { get; set; }

    public virtual DbSet<T042communicator> T042communicators { get; set; }

    public virtual DbSet<V002readerNovelWithT001readerWithT031novelWithT011author> V002readerNovelWithT001readerWithT031novelWithT011authors { get; set; }

    public virtual DbSet<V011auWith031NoWith032ChWith022Admin> V011auWith031NoWith032ChWith022Admins { get; set; }

    public virtual DbSet<V031novelWith011Author> V031novelWith011Authors { get; set; }

    public virtual DbSet<V031novelWith032Chapter> V031novelWith032Chapters { get; set; }

    public virtual DbSet<V041messageWith011AuthorWith022Admin> V041messageWith011AuthorWith022Admins { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.
        => optionsBuilder.UseSqlServer("Server=localhost,5433;database=BookStore2024;uid=SA;pwd=tttt.123;TrustServerCertificate=True;");

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<T001reader>(entity =>
        {
            entity.ToTable("T001Reader");

            entity.Property(e => e.Id)
                .ValueGeneratedNever()
                .HasComment("读者Id");
            entity.Property(e => e.Email)
                .HasMaxLength(50)
                .HasComment("读者邮箱");
            entity.Property(e => e.NickName)
                .HasMaxLength(50)
                .HasComment("读者昵称");
            entity.Property(e => e.Password)
                .HasMaxLength(50)
                .HasComment("密码");
            entity.Property(e => e.TelephoneNumber).HasComment("读者电话");
            entity.Property(e => e.UserName)
                .HasMaxLength(50)
                .HasComment("读者姓名");
        });

        modelBuilder.Entity<T002readerNovel>(entity =>
        {
            entity.ToTable("T002Reader-Novel");

            entity.Property(e => e.Id)
                .ValueGeneratedNever()
                .HasComment("读书记录的Id");
            entity.Property(e => e.IsCollected).HasComment("是否被收藏");
            entity.Property(e => e.LastViewedChapter).HasComment("上次读到的章节");
            entity.Property(e => e.NovelId).HasComment("小说Id");
            entity.Property(e => e.ReaderId).HasComment("读者Id");

            entity.HasOne(d => d.Novel).WithMany(p => p.T002readerNovels)
                .HasForeignKey(d => d.NovelId)
                .HasConstraintName("FK_T002Reader-Novel_T031Novels");

            entity.HasOne(d => d.Reader).WithMany(p => p.T002readerNovels)
                .HasForeignKey(d => d.ReaderId)
                .OnDelete(DeleteBehavior.Cascade)
                .HasConstraintName("FK_T002Reader-Novel_T001Reader");
        });

        modelBuilder.Entity<T011author>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK_T002Author");

            entity.ToTable("T011Author");

            entity.Property(e => e.Id)
                .ValueGeneratedNever()
                .HasComment("作者Id");
            entity.Property(e => e.AdministratorId).HasComment("指定管理员ID");
            entity.Property(e => e.AuthorProfile).HasComment("作者简介");
            entity.Property(e => e.Email)
                .HasMaxLength(50)
                .HasComment("作者邮箱");
            entity.Property(e => e.NickName)
                .HasMaxLength(50)
                .HasComment("昵称");
            entity.Property(e => e.Password)
                .HasMaxLength(50)
                .HasComment("密码");
            entity.Property(e => e.TelephoneNumber).HasComment("作者电话");
            entity.Property(e => e.UserName)
                .HasMaxLength(50)
                .HasComment("用户名");

            entity.HasOne(d => d.Administrator).WithMany(p => p.T011authors)
                .HasForeignKey(d => d.AdministratorId)
                .OnDelete(DeleteBehavior.SetNull)
                .HasConstraintName("FK_T011Author_T022Administrators");
        });

        modelBuilder.Entity<T021chiefAdministrator>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK_T003ChiefAdministrator");

            entity.ToTable("T021ChiefAdministrator");

            entity.Property(e => e.Id)
                .ValueGeneratedNever()
                .HasComment("总管理员Id");
            entity.Property(e => e.Password)
                .HasMaxLength(50)
                .HasComment("主管理员密码");
            entity.Property(e => e.UserName)
                .HasMaxLength(50)
                .HasComment("主管理员姓名");
        });

        modelBuilder.Entity<T022administrator>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK_T004Administrators");

            entity.ToTable("T022Administrator");

            entity.Property(e => e.Id)
                .ValueGeneratedNever()
                .HasComment("管理员Id");
            entity.Property(e => e.Password)
                .HasMaxLength(50)
                .HasComment("密码");
            entity.Property(e => e.UserName)
                .HasMaxLength(50)
                .HasComment("管理员姓名");
        });

        modelBuilder.Entity<T031novel>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK_T007Novels");

            entity.ToTable("T031Novel");

            entity.Property(e => e.Id)
                .ValueGeneratedNever()
                .HasComment("小说Id");
            entity.Property(e => e.AuthorId).HasComment("小说作者的Id");
            entity.Property(e => e.IsEnd).HasComment("小说是否完结");
            entity.Property(e => e.IsToAdmin).HasComment("小说是否提交给管理员审核");
            entity.Property(e => e.NovelGenerateTime)
                .HasComment("小说产生的时间")
                .HasColumnType("datetime");
            entity.Property(e => e.NovelImageAddress)
                .HasMaxLength(50)
                .HasComment("小说封面地址");
            entity.Property(e => e.NovelTitle)
                .HasMaxLength(50)
                .HasComment("小说标题");
            entity.Property(e => e.NovelTotalWords).HasComment("小说总字数");
            entity.Property(e => e.OnShelf).HasComment("小说是否上架");
            entity.Property(e => e.Profile)
                .HasMaxLength(50)
                .HasComment("小说简介");
            entity.Property(e => e.Status)
                .HasMaxLength(50)
                .HasDefaultValue("Draft")
                .HasComment("小说审核状态");
            entity.Property(e => e.TotalChapters).HasComment("小说总的章节数");
            entity.Property(e => e.Type)
                .HasMaxLength(50)
                .HasComment("小说类型");
            entity.Property(e => e.UpdateToChapter).HasComment("目前更新到第几章");
        });

        modelBuilder.Entity<T032chapter>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK_T006Chapters");

            entity.ToTable("T032Chapter", tb =>
                {
                    tb.HasTrigger("trg_AfterChapterChange_UpdateUpdateToChapter");
                    tb.HasTrigger("trg_AfterDelete");
                    tb.HasTrigger("trg_AfterInsert_UpdateChapterTotalWords");
                });

            entity.Property(e => e.Id)
                .ValueGeneratedNever()
                .HasComment("章节Id");
            entity.Property(e => e.ChapterGenerateTime)
                .HasComment("章节创造时间")
                .HasColumnType("datetime");
            entity.Property(e => e.ChapterNumber).HasComment("章节编号");
            entity.Property(e => e.ChapterPublishTime)
                .HasComment("章节发送时间")
                .HasColumnType("datetime");
            entity.Property(e => e.ChapterText).HasComment("章节内容");
            entity.Property(e => e.ChapterTitle)
                .HasMaxLength(50)
                .HasComment("章节标题");
            entity.Property(e => e.ChapterTotalWords).HasComment("章节总字数");
            entity.Property(e => e.LastModifyTime)
                .HasComment("最后修改时间")
                .HasColumnType("datetime");
            entity.Property(e => e.NovelId).HasComment("所属小说Id");
            entity.Property(e => e.Status)
                .HasMaxLength(50)
                .HasDefaultValue("Draft");

            entity.HasOne(d => d.Novel).WithMany(p => p.T032chapters)
                .HasForeignKey(d => d.NovelId)
                .HasConstraintName("FK_T032Chapters_T031Novels");
        });

        modelBuilder.Entity<T041message>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK_T005Messages");

            entity.ToTable("T041Message");

            entity.Property(e => e.Id)
                .ValueGeneratedNever()
                .HasComment("消息Id");
            entity.Property(e => e.GenerateTime)
                .HasComment("发送时间")
                .HasColumnType("datetime");
            entity.Property(e => e.IsRead).HasComment("是否已读");
            entity.Property(e => e.IsSend).HasComment("是否发送");
            entity.Property(e => e.Mcontent)
                .HasComment("发送消息")
                .HasColumnName("MContent");
            entity.Property(e => e.ReceiverId).HasComment("接收者姓名");
            entity.Property(e => e.ReceiverRole)
                .HasMaxLength(50)
                .HasComment("接收者角色");
            entity.Property(e => e.SenderId).HasComment("发送者姓名");
            entity.Property(e => e.SenderRole)
                .HasMaxLength(50)
                .HasComment("发送者角色");
        });

        modelBuilder.Entity<T042communicator>(entity =>
        {
            entity.ToTable("T042Communicator");

            entity.Property(e => e.Id)
                .ValueGeneratedNever()
                .HasComment("通信人Id");
            entity.Property(e => e.Name)
                .HasMaxLength(50)
                .HasComment("通信人姓名");
            entity.Property(e => e.NickName)
                .HasMaxLength(50)
                .HasComment("通信人的昵称");
            entity.Property(e => e.Role)
                .HasMaxLength(10)
                .HasComment("通信人身份");
        });

        modelBuilder.Entity<V002readerNovelWithT001readerWithT031novelWithT011author>(entity =>
        {
            entity
                .HasNoKey()
                .ToView("V002Reader-NovelWithT001ReaderWithT031NovelWithT011Author");

            entity.Property(e => e.AuthorNickName).HasMaxLength(50);
            entity.Property(e => e.NovelImageAddress).HasMaxLength(50);
            entity.Property(e => e.NovelTitle).HasMaxLength(50);
            entity.Property(e => e.Profile).HasMaxLength(50);
            entity.Property(e => e.ReaderNickName).HasMaxLength(50);
            entity.Property(e => e.Type).HasMaxLength(50);
        });

        modelBuilder.Entity<V011auWith031NoWith032ChWith022Admin>(entity =>
        {
            entity
                .HasNoKey()
                .ToView("V011AuWith031NoWith032ChWith022Admin");
        });

        modelBuilder.Entity<V031novelWith011Author>(entity =>
        {
            entity
                .HasNoKey()
                .ToView("V031NovelWith011Author");

            entity.Property(e => e.AuthorNickName).HasMaxLength(50);
            entity.Property(e => e.NovelGenerateTime).HasColumnType("datetime");
            entity.Property(e => e.NovelImageAddress).HasMaxLength(50);
            entity.Property(e => e.NovelTitle).HasMaxLength(50);
            entity.Property(e => e.Profile).HasMaxLength(50);
            entity.Property(e => e.Type).HasMaxLength(50);
        });

        modelBuilder.Entity<V031novelWith032Chapter>(entity =>
        {
            entity
                .HasNoKey()
                .ToView("V031NovelWith032Chapter");

            entity.Property(e => e.ChapterGenerateTime).HasColumnType("datetime");
            entity.Property(e => e.ChapterPublishTime).HasColumnType("datetime");
            entity.Property(e => e.ChapterTitle).HasMaxLength(50);
            entity.Property(e => e.LastModifyTime).HasColumnType("datetime");
            entity.Property(e => e.NovelImageAddress).HasMaxLength(50);
            entity.Property(e => e.NovelTitle).HasMaxLength(50);
            entity.Property(e => e.Status).HasMaxLength(50);
            entity.Property(e => e.Type).HasMaxLength(50);
        });

        modelBuilder.Entity<V041messageWith011AuthorWith022Admin>(entity =>
        {
            entity
                .HasNoKey()
                .ToView("V041MessageWith011AuthorWith022Admin");

            entity.Property(e => e.GenerateTime).HasColumnType("datetime");
            entity.Property(e => e.ReceiverName).HasMaxLength(50);
            entity.Property(e => e.ReceiverRole).HasMaxLength(50);
            entity.Property(e => e.SenderName).HasMaxLength(50);
            entity.Property(e => e.SenderRole).HasMaxLength(50);
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
